package com.pay.manager.controller.system;




import com.pay.manager.dto.MerchantSearchDTO;
import com.pay.manager.response.PageDataResult;
import com.pay.manager.service.MerchantService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;


/**
 * @Title: MerchantController
 * @Description: 商户管理
 * @author: yjw
 * @version: 1.0
 * @date: 2020/06/12 15:17
 */
@Controller
@RequestMapping("merchant")
public class MerchantController {

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private MerchantService merchantService;

	@RequestMapping("/merchantManage")
	public String toPage() {
		logger.info("进入商户信息管理");
		return "/merchant/merchantManage";
	}
	
	@RequestMapping("/merchantApply")
	public String goPage() {
		logger.info("进入商户申请管理");

		return "/merchant/merchantApply";
	}
	/**
	 *
	 * 功能描述: 分页查询用户列表
	 *
	 * @param:
	 * @return:
	 * @date: 2018/11/21 11:10
	 */
	@RequestMapping(value = "/getMerchantList", method = RequestMethod.POST)
	@ResponseBody
	public PageDataResult getMerchantList(@RequestParam("pageNum") Integer pageNum,
									   @RequestParam("pageSize") Integer pageSize, /* @Valid PageRequest page, */ MerchantSearchDTO merchantSearch) {
		/*
		 * logger.info("分页查询用户列表！搜索条件：userSearch：" + userSearch + ",pageNum:" +
		 * page.getPageNum() + ",每页记录数量pageSize:" + page.getPageSize());
		 */

		PageDataResult pdr = new PageDataResult();
		try {
			if (null == pageNum) {
				pageNum = 1;
			}
			if (null == pageSize) {
				pageSize = 10;
			}
			// 获取用户列表
			pdr = merchantService.getMerchantList(merchantSearch, pageNum, pageSize);
			logger.info("商户信息列表查询=pdr:" + pdr);

		} catch (Exception e) {
			e.printStackTrace();
			logger.error("商户信息列表查询异常！", e);
		}
		return pdr;
	}
	
	@RequestMapping(value = "/getMerchantApplyList", method = RequestMethod.POST)
	@ResponseBody
	public PageDataResult getMerchantApplyList(@RequestParam("pageNum") Integer pageNum,
			@RequestParam("pageSize") Integer pageSize, /* @Valid PageRequest page, */ MerchantSearchDTO merchantSearch) {
		/*
		 * logger.info("分页查询用户列表！搜索条件：userSearch：" + userSearch + ",pageNum:" +
		 * page.getPageNum() + ",每页记录数量pageSize:" + page.getPageSize());
		 */
		PageDataResult pdr = new PageDataResult();
		try {
			if (null == pageNum) {
				pageNum = 1;
			}
			if (null == pageSize) {
				pageSize = 10;
			}
			// 获取用户列表
			pdr = merchantService.getMerchantApplyList(merchantSearch, pageNum, pageSize);
			logger.info("商户申请列表查询=pdr:" + pdr);

		} catch (Exception e) {
			e.printStackTrace();
			logger.error("审核申请处理列表查询异常！", e);
		}
		return pdr;
	}
	
	 @RequestMapping(value = "/applyPass", method = RequestMethod.POST)
	 @ResponseBody 
	 public Map<String,Object> applyPass(Integer mid, String operationPwd) {
		 logger.info("商户编号为"+mid+"的认证审核通过了！");
		 System.out.println(mid+","+operationPwd);
		 Map<String,Object> data = new HashMap();
		 data = merchantService.applyPass(mid,operationPwd);
		 return data;
	}
	 

	 @RequestMapping(value = "/updateMerchant", method = RequestMethod.POST)
	 @ResponseBody 
	 public Map<String,Object> updateMerchant(Integer mid,String merchantName,String merchantType,String merchantAddress,String username,String mobile,String contactsAddress,String operationPwd) {
		 logger.info("商户编号为"+mid+"的商户信息进行了修改！");
		 System.out.println(mid+","+merchantName+","+merchantType);
		 Map<String,Object> data = merchantService.updateMerchant(mid,merchantName,merchantType,merchantAddress,username,mobile,contactsAddress,operationPwd);
		 return data;
	}
	 
	 
	 @RequestMapping(value = "/lower", method = RequestMethod.POST)
	 @ResponseBody 
	 public Map<String,Object> lower(Integer mid,String state,String operationPwd) {
		 logger.info("商户编号为"+mid+"的认证审核失败！");
		 Map<String,Object> data = merchantService.lower(mid,state,operationPwd);
		 return data;
	}

}
